// Facebook post model
window.FBPost = Backbone.Model.extend({
  defaults: {
    id: "", // message ID
    message: "", // Fb message
    time: "", // publish date & hour
    likes: 0, // number of likes for the post
    comments: 0, // number of comments for the post
    from_id: "", // author's Fb ID
    from_name: "", // author's name
    from_picture: "img/fb-default.gif",
    from_page: 0, // 0 for Fb user, 1 for Fb page
    // position displayed with %
    pos_x: 0,
    pos_y: 0
  },

  url: "http://remiduriez.free.fr/socagora"
});

// Facebook post collection
window.FBPosts = Backbone.Collection.extend({
  model: FBPost,

  // check if a fbPost is in the collection
  isIncluded: function(fbPost) {
    var posts = this.where({id: fbPost.id});
    if (posts.length>0)
      return true;
    else
      return false;
  },

  // return the older post
  getOlder: function() {
    var older = fbPosts.at(0);
    for (i=1; i<fbPosts.length; i++) {
      if (fbPosts.at(i).get('time') < older.get('time'))
        older = fbPosts.at(i);
    }
    return older;
  }
});

window.fbPosts = new FBPosts();